/**
 * Copyright (c) 2013-2022 Nikita Koksharov
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.redisson.client.protocol.convertor;


/**
 * 实现了将对象转换为Byte类型的转换器。
 * 该转换器主要用于处理需要将各种类型的对象转换为Byte类型的情况。
 */
public class ByteReplayConvertor implements Convertor<Byte> {

    /**
     * 将给定的对象转换为Byte类型。
     *
     * @param obj 需要转换的对象。可以是任何类型的对象，但最终将尝试将其转换为Byte类型。
     * @return 转换后的Byte类型。如果输入的obj为null，则返回0。
     *         该方法通过调用obj的toString方法，然后使用valueOf方法将其转换为Byte类型。
     */
    @Override
    public Byte convert(Object obj) {
        if (obj == null) {
            return 0;
        }
        return Byte.valueOf(obj.toString());
    }
}

